const UserDao = require("../dao/user/user_dao.js");
const LoginService = {
   login(req,res,next){
       const {username,password} = req.body;

        UserDao.find({username})
               .then((data)=>{
                console.log(data);
                    if(data.length === 1 ){//存在
                        //比较密码
                        if(password === data[0].password){
                            res.json({
                            res_code:1,
                            res_error:"",
                            res_body:{
                                status:1,
                                message:"success",
                                data:{
                                    username:data[0].username,
                                }
                        }});

                        }else{
                            res.json({
                            res_code:1,
                            res_error:"",
                            res_body:{
                                status:0,
                                message:"密码错误",
                                data:{

                                }
                        }});

                        }
                    }else{
                        res.json({
                            res_code:1,
                            res_error:"",
                            res_body:{
                                status:0,
                                message:"用户名不存在",
                                data:{

                                }
                        }});

                    }
               })
               .catch((err)=>{
                 res.json({res_code:0,res_error:"",res_body:{}})
               });

    },
};
module.exports = LoginService;

